﻿using System;
using System.Windows;
using System.Windows.Media.Imaging;
using Blackbird.Core.Editable.Frames;
using Blackbird.Editors.Sample;
using Microsoft.Win32;

namespace Blackbird.Editors
{
    /// <summary>
    /// Interaction logic for FramesetEditorWindow.xaml
    /// </summary>
    public partial class FramesetEditorWindow
    {
        // Using a DependencyProperty as the backing store for Frameset.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty FramesetProperty =
            DependencyProperty.Register("Frameset", typeof (EditableFrameset), typeof (FramesetEditorWindow),
                                        new UIPropertyMetadata(new EditableFrameset(), BindImages));

        public FramesetEditorWindow()
        {
            InitializeComponent();
        }

        public EditableFrame SelectedFrame { get; set; }

        public EditableFrameset Frameset
        {
            get { return (EditableFrameset) GetValue(FramesetProperty); }
            set { SetValue(FramesetProperty, value); }
        }

        private void SampleButtonClick(object sender, RoutedEventArgs e)
        {
            Frameset = SampleGenerator.GenerateFrameset();
        }

        private static void BindImages(DependencyObject sender, DependencyPropertyChangedEventArgs args)
        {
            //FrameItemsListBox.Items.Clear();
            //FrameItemsListBox.ItemsSource = Frameset.Where(f => f.Width > 0);
        }

        private void UpdateFrameButtonClick(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog
                             {
                                 Filter =
                                     "Portable Network Graphics (*.png)|*.png|Bitmaps (*.bmp)|*.bmp|All Files (*.*)|*.*"
                             };
            bool? result = dialog.ShowDialog();
            if (result.Value)
            {
                SelectedFrame.BitmapSource = new BitmapImage(new Uri(dialog.FileName));
            }
        }
    }
}